package com.ss.android.newmedia.message.dialog;

import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.PathInterpolator;

import com.ss.android.messagebus.Subscriber;
import com.ss.android.messagebus.SubscriptionRouter;

public final class a {
    private static boolean b;

    static {
        b = false;
    }

    public c a;
    private Activity c;
    private View d;
    private ScrollLayout e;
    private WindowManager f;
    private WindowManager.LayoutParams g;
    private b h;
    private Handler i;
    private int j;
    private int k;
    private int l;
    private boolean m;
    private boolean n;
    private boolean o;
    private boolean p;
    private boolean q;
    private Runnable r;
    private ValueAnimator s;
    private ValueAnimator t;

    public a(Activity arg8, View arg9, b arg10) {
        this.i = new Handler(Looper.getMainLooper());
        this.m = true;
        this.n = true;
        this.o = false;
        this.p = false;
        this.q = false;
        this.r = new com.ss.android.newmedia.message.dialog.b(this);
        this.c = arg8;
        this.d = arg9;
        this.h = arg10;
        if (this.h == null) {
            this.h = new b(((Context) arg8));
        }

        this.e = (ScrollLayout) LayoutInflater.from(arg8).inflate(com.ss.android.article.browser.R.layout.dr, null);
        this.e.addView(arg9);
        this.f = (WindowManager) this.c.getSystemService(Context.WINDOW_SERVICE);
        this.g = new WindowManager.LayoutParams(-1, -2, 2, 520, -3);
        this.g.gravity = 80;
        this.e.measure(0, 0);
        WindowManager.LayoutParams v0 = this.g;
        int v1 = -this.e.getMeasuredHeight();
        this.k = v1;
        v0.y = v1;
        this.l = this.h.b;
    }

    public a(Activity arg2, View arg3) {
        this(arg2, arg3, new b(arg2));
    }

    static ValueAnimator a(a arg1) {
        return arg1.s;
    }

    static void a(a arg0, boolean arg1, boolean arg2) {
        arg0.a(arg1, arg2);
    }

    static boolean a(a arg0, boolean arg1) {
        arg0.o = arg1;
        return arg1;
    }

    static int a(a arg0, int arg1) {
        arg0.j = arg1;
        return arg1;
    }

    static ValueAnimator a(a arg0, ValueAnimator arg1) {
        arg0.s = arg1;
        return arg1;
    }

    static ValueAnimator b(a arg1) {
        return arg1.t;
    }

    static void b(a arg6, boolean arg7) {
        TimeInterpolator v1;
        ObjectAnimator v0_1;
        float[] v2_1;
        View v0;
        int v2 = 2;
        if (arg7) {
            v0 = arg6.d;
            v2_1 = new float[v2];
            v2_1[0] = ((float) arg6.j);
            v2_1[1] = ((float) arg6.d.getMeasuredWidth());
            v0_1 = ObjectAnimator.ofFloat(v0, "translationX", v2_1);
        } else {
            v0 = arg6.d;
            v2_1 = new float[v2];
            v2_1[0] = ((float) arg6.j);
            v2_1[1] = ((float) (-arg6.d.getMeasuredWidth()));
            v0_1 = ObjectAnimator.ofFloat(v0, "translationX", v2_1);
        }

        v0_1.addListener(new i(arg6));
        if (Build.VERSION.SDK_INT > 21) {
            v1 = new PathInterpolator(0.4f, 0.8f, 0.74f, 1f);
        } else {
            v1 = new DecelerateInterpolator();
        }

        v0_1.setInterpolator(v1);
        v0_1.setDuration(200);
        v0_1.start();
    }

    static void b(a arg3, int arg4) {
        float v0 = 1f;
        float v1 = v0 - (v0 - arg3.h.f) / (((float) arg3.h.e)) * (((float) Math.abs(arg4)));
        if (v1 < arg3.h.f) {
            v1 = arg3.h.f;
        }

        if (v1 <= v0) {
            v0 = v1;
        }

        arg3.d.setScaleX(v0);
        arg3.d.setScaleY(v0);
    }

    static void b(a arg0, boolean arg1, boolean arg2) {
        arg0.b(arg1, arg2);
    }

    public static boolean b() {
        return b;
    }

    static boolean c(a arg1) {
        return arg1.m;
    }

    static int d(a arg1) {
        return arg1.j;
    }

    static View e(a arg1) {
        return arg1.d;
    }

    static boolean f(a arg1) {
        return arg1.n;
    }

    static WindowManager.LayoutParams g(a arg1) {
        return arg1.g;
    }

    static int h(a arg1) {
        return arg1.k;
    }

    static int i(a arg1) {
        return arg1.l;
    }

    static void j(a arg3) {
        try {
            arg3.f.updateViewLayout(arg3.e, arg3.g);
        } catch (Exception v0) {
            v0.printStackTrace();
        }
    }

    static void k(a arg4) {
        ValueAnimator v0 = ValueAnimator.ofInt(new int[]{arg4.g.y, arg4.l});
        v0.addUpdateListener(new h(arg4));
        v0.setInterpolator(new a$a());
        v0.setDuration(200);
        v0.start();
    }

    static boolean l(a arg1) {
        return arg1.p;
    }

    static Runnable m(a arg1) {
        return arg1.r;
    }

    static Handler n(a arg1) {
        return arg1.i;
    }

    static b o(a arg1) {
        return arg1.h;
    }

    static void p(a arg5) {
        ObjectAnimator v0 = ObjectAnimator.ofFloat(arg5.d, "translationX", new float[]{((float) arg5.j), 0f});
        v0.addUpdateListener(new j(arg5));
        v0.setDuration(200);
        v0.start();
    }

    static boolean q(a arg1) {
        return arg1.o;
    }

    static boolean r(a arg1) {
        return arg1.q;
    }

    static boolean s(a arg1) {
        arg1.p = true;
        return true;
    }

    static ScrollLayout t(a arg1) {
        return arg1.e;
    }

    static WindowManager u(a arg1) {
        return arg1.f;
    }

    public final boolean a() {
        boolean v0 = true;
        try {
            this.f.addView(this.e, this.g);
            this.e.post(new com.ss.android.newmedia.message.dialog.c(this));
            b = true;
            this.q = true;
            SubscriptionRouter.addSubscriber(this);
            this.e.setOnScrollListener(new ScrollLayout.a(this));
            if (this.h.a > 0) {
                this.i.removeCallbacks(this.r);
                this.i.postDelayed(this.r, ((long) this.h.a));
            }

            if (this.a == null) {
                return v0;
            }

            this.a.a();
        } catch (Exception v0_1) {
            v0 = false;
        }

        return v0;
    }

    public final void a(boolean arg2) {
        if (arg2) {
            this.a(false, false);
        } else {
            this.b(false, false);
        }
    }

    private void a(boolean arg6, boolean arg7) {
        TimeInterpolator v0_1;
        this.t = ValueAnimator.ofInt(new int[]{this.g.y, -this.e.getMeasuredHeight()});
        this.t.addUpdateListener(new f(this));
        this.t.addListener(new g(this, arg6, arg7));
        this.t.setInterpolator(new a$a());
        this.t.setDuration(200);
        if (Build.VERSION.SDK_INT > 21) {
            v0_1 = new PathInterpolator(0.4f, 0.8f, 0.74f, 1f);
        } else {
            v0_1 = new DecelerateInterpolator();
        }

        this.t.setInterpolator(v0_1);
        this.t.start();
    }

    private void b(boolean arg3, boolean arg4) {
        try {
            this.q = false;
            b = false;
            this.i.removeCallbacks(this.r);
            this.f.removeViewImmediate(this.e);
            if (this.a != null) {
                this.a.a(arg3, arg4);
            }

            SubscriptionRouter.removeSubscriber(this);
        } catch (Exception v0) {
        }
    }

    @Subscriber
    public final void onActivityPause$3a9c559a(android.support.design.a arg3) {
        this.b(true, false);
    }

    public interface c {
        void a(boolean arg1, boolean arg2);

        void a();
    }

    public static final class a$a implements Interpolator {
        public a$a() {

        }

        public final float getInterpolation(float arg7) {
            return ((float) (Math.pow(2, ((double) (-10f * arg7))) * Math.sin((((double) (arg7 - 0.25f))) * 6.283185) + 1));
        }
    }

    public static final class b {
        public int a;
        public int b;
        public int c;
        public int d;
        public int e;
        public float f;

        public b(Context arg4) {
            this.a = 6000;
            this.b = ((int) TypedValue.applyDimension(1, 47f, arg4.getResources().getDisplayMetrics()));
            this.c = ((int) TypedValue.applyDimension(1, 60f, arg4.getResources().getDisplayMetrics()));
            this.d = ((int) TypedValue.applyDimension(1, 20f, arg4.getResources().getDisplayMetrics()));
            this.e = ((int) TypedValue.applyDimension(1, 10f, arg4.getResources().getDisplayMetrics()));
            this.f = 0.96f;
        }
    }
}

